local window, io, string, milena, table, tostring, dofile, file_exists, lfs, os = window, io, string, milena, table, tostring, dofile, file_exists, lfs, os
module("config")
dir = milena.startdir
portable = true
function save()
	local fullscreen = tostring(window.fullscreen)
	if window.fullscreen then
		window.fullscreen = false
	end
	local str = ("window.left = %d\
window.top = %d\
window.right = %d\
window.bottom = %d\
window.fullscreen = %s"):format(window.left, window.top, window.right, window.bottom, fullscreen)
	local cfg = io.open(dir..'/config.ini', 'w')
	cfg:write(str)
	cfg:close()	
end
function load()
	if file_exists(dir..'/config.ini') then
		dofile(dir..'/config.ini')
	else
		dofile(milena.startdir..'/config.ini')
	end
end

if os.getenv("OS")=="Windows_NT" and not portable then
	lfs.mkdir(os.getenv("USERPROFILE")..'/AppData/Local/Milena')
	lfs.mkdir(os.getenv("USERPROFILE")..'/AppData/Local/Milena/config')
	dir = os.getenv("USERPROFILE")..'/AppData/Local/Milena/config'
end


table.insert(milena.exit, save)